package com.rakuten.api.mule.transformers;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.codehaus.jackson.annotate.JsonAutoDetect;
import org.codehaus.jackson.map.ObjectMapper;
import org.codehaus.jackson.type.TypeReference;
import org.mule.api.MuleMessage;
import org.mule.api.transformer.TransformerException;
import org.mule.api.transport.PropertyScope;
import org.mule.transformer.AbstractMessageTransformer;

import com.rakuten.api.mule.CommonFlowConstants;
import com.rakuten.api.mule.model.Product;
import com.rakuten.api.mule.model.Variants;
@JsonAutoDetect
public class JsonToShopObject extends AbstractMessageTransformer{
	@Override
	public Object transformMessage(MuleMessage message, String outputEncoding)
			throws TransformerException {
		Map<String,Object> map = new HashMap<String,Object>();
		try {
			
			ObjectMapper mapper = new ObjectMapper();
			//convert JSON string to Map
			map = mapper.readValue(message.getPayloadAsString(), 
			    new TypeReference<HashMap<String,Object>>(){});
	        return map;			
		} catch (Exception ex) {
			throw new TransformerException(this, ex);
		}
	}

}
